//
// Created by Jiangmingz on 16/1/26.
// Copyright (c) 2016 SunYuanYang. All rights reserved.
//

#import "HttpManager.h"

#import "HttpConstant.h"

@implementation HttpManager

- (instancetype)init {
    self = [super init];
    if (self) {
        [self configure];
    }

    return self;
}

+ (instancetype)share {
    static HttpManager *httpManager;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        httpManager = [[HttpManager alloc] init];
    });

    return httpManager;
}

- (void)configure {
    self.requestSerializer = [AFHTTPRequestSerializer serializer];
    [self.requestSerializer setTimeoutInterval:kDefaultHttpTimeout];

    AFJSONResponseSerializer *responseSerializer = [AFJSONResponseSerializer serializer];
    responseSerializer.removesKeysWithNullValues = YES;
    self.responseSerializer = responseSerializer;
    self.responseSerializer.acceptableContentTypes = [self.responseSerializer.acceptableContentTypes setByAddingObjectsFromArray:@[@"text/html", @"text/plain"]];
}

- (NSString *)host2DNS:(NSString *)host {
    return host;
}

- (NSString *)token {
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    NSString *token = [userDefaults objectForKey:kWQUserDefaultKeyToken];
    return token;
}

@end
